<?php

class Role_model extends Model {
	
	/**
	 * 创建角色
	 * @param unknown_type $cols
	 */
	public function createRole($cols) {
		$dRole = new Role_data();
		
		return $dRole->createRole($cols);
	}

	/**
	 * 删除角色
	 * @param unknown_type $id
	 */
	public function deleteRole($params) {
		$dRole = new Role_data();
		
		return $dRole->deleteRole($params);
	}

	/**
	 * 根据ID编辑角色信息
	 * @param unknown_type $id
	 * @param unknown_type $role
	 */
	public function editRoleById($roleId, $cols) {
		$dRole = new Role_data();
		
		$params['role_id'] = $roleId;
		return $dRole->editRole($params, $cols);
	}

	/**
	 * 根据ID获取角色信息
	 * @param unknown_type $id
	 */
	public function roleById($roleId) {
		$dRole = new Role_data();
		
		$params['role_id'] = $roleId;
		return $dRole->role($params);
	}

	/**
	 * 获取角色信息
	 * @param unknown_type $params
	 */
	public function roles($params) {
		$dRole = new Role_data();
		
		return $dRole->roles($params);
	}
	/**
	 * 分页获取角色信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderby
	 */
	public function page($page, $size, $params = array(), $orderby='`role_id` DESC') {
		$dRole = new Role_data();
		
		$num = $dRole->count($params);
		if($num === false) return false;
		if($num === 0) return array('num' => 0, 'data' => array(), 'page' => $page, 'size' => $size);
		
		$result = $dRole->page($page, $size, $params, $orderby);
		if(!$result) return false;
		return array('num' => $num, 'data' => $result, 'page' => $page, 'size' => $size);
	}
}